<template>
  <div class="card-edit-toolbar">
    <div class="card-edit-toolbar-left">
      <div class="card-edit-toolbar-left-box" style="transform: scale(0.65)">
        <div class="card-phone-menu-toolbar-left">
          <!-- card-phone-menu -->
          <p> {{ pageInfo.title_top || '标题' }} </p>
        </div>

        <CardPhoneView
          class="scroll-bar-cls card-phone-view-toolbar-left"
          :cardLists="pages[curPage]"
          :scale="1"
          style="transform: scale(1)">
        </CardPhoneView>

        <div v-if="pageInfo.toolbar_menus && pageInfo.toolbar_menus.length > 0" class="card-phone-toolbar">
          <div :key="index" class="card-phone-toolbar-menu" v-for="(menu, index) in pageInfo.toolbar_menus">
            <div class="card-phone-toolbar-menu-box">
              <img :src="menu.pic" alt="" height="24" width="24">
              <h4>{{menu.name}}</h4>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="card-edit-toolbar-right scroll-bar-cls">
      <div class="card-edit-toolbar-right-list">
        <CardEditToolbarRecursion></CardEditToolbarRecursion>
      </div>

      <div class="card-edit-toolbar-right-btns" v-if="!bIsToolbar">
        <el-button type="primary" size="small" round @click="handlerAddToolbar">添加底导</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  import CardPhoneView from '@/views/card/content/CardPhoneView.vue';
  import { CardSiteDataEditableParamsLists } from '@/views/card/js/data/cardSiteData';
  import { isArray, isHasOwnProperty } from '@/utils/public.js';
  import { defineAsyncComponent } from 'vue';
  import { mapState, mapActions } from 'vuex';
  export default {
    data() {
      return {
        CardSiteDataEditableParamsLists: CardSiteDataEditableParamsLists,
      }
    },
    computed: {
      ...mapState({
        pageInfo: state => _.cloneDeep(state.cardComponents.siteData.attrs),
        pages: state => _.cloneDeep(state.cardComponents.siteData.pages),
        curPage: state => state.cardComponents.curPage,
      }),
      bIsToolbar() {
        return this.pageInfo && isHasOwnProperty(this.pageInfo, 'toolbar_menus');
      },
    },
    components: {
      CardPhoneView,

      'CardEditToolbarRecursion': defineAsyncComponent(() => import('@/views/card/more/toolbar/CardEditToolbarRecursion.vue')),
    },
    methods: {
      ...mapActions({
        updateCardPageInfo: 'cardComponents/updateCardPageInfo',
      }),
      /* init */
      onChangePageInfo(args, index, key) {
        let newPageInfo = _.cloneDeep(this.pageInfo);
        newPageInfo.toolbar_menus[index][key] = args[0];
        this.updateCardPageInfo(newPageInfo);
      },

      /* toolbar */
      handlerAddToolbar() {
        const newPageInfo = _.cloneDeep(this.pageInfo);
        const { toolbar_menus } = newPageInfo;
        if( !isArray(toolbar_menus) ) newPageInfo.toolbar_menus = [];
        this.updateCardPageInfo(newPageInfo);
      },
    },
  }
</script>

<style lang="scss">
  .card-edit-toolbar {
    position: relative;
    display: flex;
    height: 100%;

    .card-edit-toolbar-left {
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 375px;
      height: 100%;
      background: #E4E7EB;

      .card-edit-toolbar-left-box {
        width: 100%;
      }

      .card-phone-menu-toolbar-left {
        position: relative;
        // width: 381px;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        flex-shrink: 0;

        width: 375px;
        height: 64px;
        margin: 0 1px;
        // background-image: url('//static.hd.xxx.com/jye/fe-web/images/phone-menu.png');
        background-image: url('https://static.hd.xxx.com/upload/biz/1/667487.png');
        // background: #aaa;

        p {
          position: absolute;
          bottom: 10px;
          width: 100%;
          font-size: 18px;
          color: #333;
          text-align: center;
        }
      }

      .card-phone-view-toolbar-left {
        position: relative;
        top: initial;
        left: initial;
        flex-shrink: 0;
        overflow-y: auto;
      }

      .card-phone-toolbar {
        position: relative;
        display: flex;
        justify-content: center;
        width: 100%;
        height: 45px;
        background: #f9f9f9;
        box-shadow: inset 0 1px 0 0 #fff, 0 -2px 2px -1px rgba(0,0,0,.15);

        .card-phone-toolbar-menu {
          flex: 1;
          flex-shrink: 0;
          min-width: 0;

          .card-phone-toolbar-menu-box {
            position: relative;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #939393;
            height: 100%;

            h4 {
              display: inline-block;
              margin-left: 4px;
              white-space: nowrap;
              text-overflow: ellipsis;
              overflow: hidden;
            }
          }
        }
      }
    }

    .card-edit-toolbar-right {
      position: relative;
      min-width: 0;
      height: 100%;
      padding: 25px 20px;
      overflow: auto;
      flex: 1;

      .card-edit-toolbar-right-btns {
        position: sticky;
        bottom: 25px;
        left: 20px;
      }
    }
  }
</style>
